<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html >
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta charset="UTF-8" />
<title>OpenUI5 SDK - Demo Kit</title>
<link type="image/x-icon"
	href="resources/sap/ui/core/mimes/logo/txtonly_16x16.ico"
	rel="shortcut icon" />
<link type="image/x-icon"
	href="resources/sap/ui/core/mimes/logo/txtonly_16x16.ico" rel="icon" />
<script id="sap-ui-bootstrap" src="resources/sap-ui-core.js"
	data-sap-ui-theme="sap_bluecrystal" data-sap-ui-preload="async"
	data-sap-ui-libs="sap.ui.commons, sap.ui.ux3, sap.ui.demokit"
	data-sap-ui-bindingSyntax="complex">

</script>
<!-- the dynamic-mode-check script distinguishes between a static mode where no search is available   -->
<!-- and a rich mode where a backend provides search results. The default version of the file handles -->
<!-- the rich mode. it is replaced with a static mode version during the lightening build             -->
<script src="js/dynamic-mode-check.js"></script>
<script>
	var oDemokit;
	sap.ui
			.getCore()
			.attachInit(
					function() {

						// determine the version to display
						var sVersion;
						try {
							var oVersionInfo = sap.ui.getVersionInfo();
							sVersion = oVersionInfo.version || sap.ui.version;
						} catch (ex) {
							sVersion = sap.ui.version;
						}

						// init the UI
						oDemokit = new sap.ui.demokit.DemokitApp(
								"UI development toolkit for HTML5 - Demo Kit",
								sVersion, [ "sap_bluecrystal",
										"sap_goldreflection", "sap_hcb" ]);
						oDemokit
								.createUI(
										isDynamicInstallation(),
										oDemokit
												.getInitialPage("docs/guide/WhatsNewInUI5.html"));
						oDemokit.placeAt('ctrRoot');

						// now define content
						oDemokit.addIndex("devguidekm", {
							caption : "Developer Guide",
							url : "docs/guide/index.json"
						});

						(function() {

							function transformer(oResponse) {

								var oIndexData = oResponse;

								function transformNode(sPath, oNode) {

									if (!oNode.alias && oNode.ref) {
										var sAlias = oNode.ref.split('/')
												.slice(-1)[0];
										if (sAlias == "index.html") {
											sAlias = sPath + oNode.text + "/"
													+ "index.html";
										} else {
											sAlias = sPath + sAlias;
										}
										if (sAlias !== oNode.ref) {
											oNode.alias = sAlias;
										}
									}

									// Icon URL is computed automatically: e.g. DropDownBox -> /ValueHolders/images/ctrls/dropdownbox-icon.png
									// With the ico property it is possible to define an alternative icon.
									// If no icon is available please add "ico:false"
									if (oNode.ico !== false && oNode.ref) {
										var sIconName = oNode.ico ? oNode.ico
												: "images/ctrls/"
														+ (oNode.text
																.toLowerCase() + "-icon.png"); // TODO use first control instead?
										var sIconPrefix = oNode.ref.substring(
												0,
												oNode.ref.lastIndexOf("/") + 1);
										oNode.ico = sIconPrefix + sIconName;
									}

									if (typeof oNode.controls === "string") {
										oNode.controls = oNode.controls
												.split(/,/);
									}
									if (jQuery.isArray(oNode.controls)) {
										oDemokit.registerPageForType(oNode.ref,
												oNode.controls);
									}

									if (oNode.links) {
										for (var i = 0; i < oNode.links.length; i++) {
											transformNode(sPath + oNode.text
													+ "/", oNode.links[i]);
										}
									}
								}

								oIndexData.text = "content";
								transformNode("", oIndexData);
								oIndexData.ref = "content/Controls/index.html"; // TODO determine default from index.json
								return oIndexData;
							}

							oDemokit.addIndex("controls", {
								caption : "Controls",
								url : "content/index.json",
								themable : true,
								transformer : transformer
							});

							oDemokit.addIndex("explored", {
								caption : "Explored",
								newWindow : true,
								index : {
									ref : "explored.html",
									links : [ {
										text : "Explored",
										ref : "explored.html"
									} ]
								}
							});

						}());

						(function() {

							function transformer(oResponse) {

								var oJSDocLinks = {
									ref : "docs/api/symbols/sap.ui.html",
									links : []
								};

								/**
								 * Creates a menu item for every control and adds it to an array. The function is called recursively to read all of the xml nodes
								 * @param {Object} oPackages - The object that holds all the side menu items
								 */
								function initLinks(oPackages) {
									var $currentNode = jQuery(this), $children = $currentNode
											.children("children").children(), sPackageName = $currentNode
											.children("alias").text(), sPackageRef = "docs/api/"
											+ $currentNode.children("ref")
													.text();

									if (!(sPackageName in oPackages)) {
										oPackages[sPackageName] = {
											text : sPackageName,
											tooltip : "",
											ref : sPackageRef,
											links : []
										};
									}

									$children
											.each(function(iIndex, oChild) {
												var $child = jQuery(oChild);

												//If there are nested nodes the function is called again with the current node as a parent.
												// Otherwise the node is added to the current package
												if ($child.children("children")
														.size() > 0) {
													initLinks.call(this,
															oPackages);
												} else {
													var oChildNode = {
														text : $child.children(
																"name").text(),
														tooltip : "",
														ref : "docs/api/"
																+ $child
																		.children(
																				"ref")
																		.text(),
														links : []
													};
													addMenuItem(sPackageName,
															sPackageRef,
															oChildNode,
															oPackages);
												}
											});
								}

								/**
								 * Adds a menu item to the side navigation
								 * @param {string} sPackageName - Name of the package (eg. "sap.m" or "jQuery.device")
								 * @param {string} sPackageRef - Link to the page about the package
								 * @param {Object} oChildNode - Object that holds the information about the menu item:
								 * name of the control, link to the documentation page etc.
								 * @param {Object} oPackages - The object that holds all the menu items
								 */
								function addMenuItem(sPackageName, sPackageRef,
										oChildNode, oPackages) {
									//Adds the control page to the package category
									oPackages[sPackageName].links
											.push(oChildNode);
								}

								if (oResponse) {
									//The object that will hold the documentation menu items
									var oPackages = {};

									jQuery(oResponse.documentElement).children(
											"namespace").each(function() {
										initLinks.call(this, oPackages);
									});

									for (sItem in oPackages) {
										oJSDocLinks.links
												.push(oPackages[sItem]);
									}
								}

								//The side menu with the package names should be sorted alphabetically
								oJSDocLinks.links
										.sort(function(ofirstObject,
												oSecondObject) {
											if (ofirstObject.text > oSecondObject.text) {
												return 1;
											}

											if (ofirstObject.text < oSecondObject.text) {
												return -1;
											}

											return 0;
										});

								// TODO include in index
								oJSDocLinks.links.push({
									text : "Experimental APIs",
									tooltip : "",
									ref : "docs/api/experimental.html",
									links : []
								});
								oJSDocLinks.links.push({
									text : "Deprecated APIs",
									tooltip : "",
									ref : "docs/api/deprecation.html",
									links : []
								});
								oJSDocLinks.links.push({
									text : "Security Relevant APIs",
									tooltip : "",
									ref : "docs/api/security.html",
									links : []
								});

								return oJSDocLinks;
							}

							oDemokit.addIndex("api", {
								caption : "API Reference",
								url : "docs/api/index.xml",
								transformer : transformer
							});

						}());

						oDemokit.addIndex("demoApps", {
							caption : "Demo Apps",
							index : {
								ref : "demoapps.html",
								links : [ {
									text : "Demo Apps",
									ref : "demoapps.html"
								} ]
							}
						});

						oDemokit.addIndex("iconExplorer", {
							caption : "Icons",
							newWindow : true,
							index : {
								ref : "iconExplorer.html",
								links : [ {
									text : "Icons",
									ref : "iconExplorer.html"
								} ]
							}
						});

						oDemokit.addIndex("license", {
							caption : "License",
							index : {
								ref : "LICENSE.txt",
								links : [ {
									text : "License",
									ref : "LICENSE.txt"
								} ]
							}
						});

					});
</script>
</head>
<body class="sapUiBody" role="application">
	<div id="ctrRoot"></div>
</body>
</html>
